package com.x.linx.fenfencard.model;

import org.androidannotations.annotations.EBean;
import org.androidannotations.annotations.RootContext;

import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.google.gson.Gson;
import com.x.linx.fenfencard.model.meta.GenerateErrorListener;
import com.x.linx.fenfencard.model.meta.GenerateResponseListener;
import com.x.linx.fenfencard.model.meta.IRequestCallback;
import com.x.linx.fenfencard.model.meta.Location;
import com.x.linx.fenfencard.model.meta.ReturnOrganizeList;
import com.x.linx.fenfencard.model.meta.ReturnSignIn;
import com.x.linx.utils.D;

import android.content.Context;

@EBean
public class OrganizeProxy {
	private static final String URL_ORG_LIST = Config.URL_BASE
			+ "v1/Organize/GetOrganizes";

	// + for test
	private static final String TEST_URL_ORG_LIST = URL_ORG_LIST
			+ "?radius=65.65607&longitude=114.048396&latitude=22.625223&skip=0&limit=1";
	// - for test

	private static final String PARAM_NAME_SKIP = "skip";
	private static final String PARAM_NAME_LIMIT = "limit";
	private static final String TAG = OrganizeProxy.class.getSimpleName();

	@RootContext
	Context context;

	/**
	 * 
	 * @param skip
	 *            : skip number of list
	 * @param limit
	 *            : number of list
	 */
	public void listOrg(Location location, final int skip, final int limit,
			final IRequestCallback callback) {
		String url = URL_ORG_LIST + "?" + toGetParam(location, skip, limit);
		D.d(TAG, "listOrg(), url=" + url);
		RequestQueue mQueue = Volley.newRequestQueue(context);
		StringRequest postRequest = new StringRequest(
				Request.Method.GET,
				url,
				new GenerateResponseListener(ReturnOrganizeList.class, callback),
				new GenerateErrorListener(callback));
		mQueue.add(postRequest);
	}

	String toGetParam(Location location, final int skip, final int limit) {
		String retsString = location.toGetParam() + "&" + PARAM_NAME_SKIP + "="
				+ skip + "&" + PARAM_NAME_LIMIT + "=" + limit;
		return retsString;
	}
}
